package guitforl.wrappers

import net.miginfocom.swing.MigLayout
import guitforl.parsers.xml.XMLWidgetNodeParser._
import xml.NodeSeq
import guitforl.parsers.xml.XMLWidgetNodeParser

/**
 * Created by IntelliJ IDEA.
 * User: artem
 * Date: Jul 14, 2010
 * Time: 4:16:21 PM
 * To change this template use File | Settings | File Templates.
 */

object LayoutFactory{
	var debug = false
	private val layoutCell = "[0:0,grow %s, fill]"
	private val verticalFlowLayout = "center, flowy"
	private val horizontalFlowLayout = "center, flowx"
	private val defaultRowAndColParam = "[grow, fill]"
	private val notGrowingElement = "[fill, grow 0]"
	private val itemParam = "[0:0,grow, center, fill]"
	private val oneColumnLayout = "wrap 1"

	def buildRowLayout(panelNodes: NodeSeq) = {
    val panelBuilder = new StringBuilder
    panelNodes.foreach {node => panelBuilder.append(layoutCell.format(getCompositeHeight(node)))}
    new MigLayout(verticalFlowLayout, defaultRowAndColParam, panelBuilder.toString)
  }

  def buildColLayout(panelNodes: NodeSeq) = {
	  val panelBuilder = new StringBuilder
    panelNodes.foreach {node => panelBuilder.append(layoutCell.format(getCompositeWidth(node)))}
    new MigLayout(horizontalFlowLayout, panelBuilder.toString, defaultRowAndColParam)
  }

	def createCellLayout() = {
		new MigLayout(oneColumnLayout + isDebug, itemParam, itemParam)
	}

	def createTableWidgetLayout() = {
		new MigLayout(oneColumnLayout, defaultRowAndColParam, notGrowingElement + defaultRowAndColParam)
	}

	def createEditWidgetLayout() = {
		new MigLayout("", notGrowingElement + defaultRowAndColParam, defaultRowAndColParam)
	}

	def isDebug() = {
		if(debug) ", debug"
		else ""
	}		
}